package com.hzhc.controller.storehouse;

import com.alibaba.fastjson2.JSONObject;
import com.hzhc.common.BaseController;
import com.hzhc.entity.CntrInfo;
import com.hzhc.enumBean.ResultUtilCodeEnum;
import com.hzhc.service.CntrInfoService;
import com.hzhc.service.CntrYardService;
import com.hzhc.utils.ResultUtil;
import com.hzhc.vo.CntrInfoVo;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author dongcy
 * @date 2024/6/24 10:41
 * @description StorehouseController
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/storehouse")
public class StorehouseController extends BaseController {

    private final CntrInfoService cntrInfoService;

    private final CntrYardService cntrYardService;

    /**
     * 获取公司下的的在场箱子贝位
     * @return
     */
    @RequestMapping("/getCntrAndBayInfo")
    @ResponseBody
    public ResultUtil<JSONObject> getCntrAndBayInfo(@RequestBody CntrInfo info){
        JSONObject json = cntrInfoService.getCntrBayInfo(info);
        return ResultUtil.build(json, ResultUtilCodeEnum.SUCCESS);
    }

    /**
     * 贝位详情
     * @param bay
     * @return
     */
    @GetMapping("/detail/{bay}")
    public ResultUtil<JSONObject> getDetail(@PathVariable("bay") String bay){
        String[] split = bay.split("-");
        if(Integer.parseInt(split[2])<10){
            split[2]="0"+split[2];
        }else{
            split[2]=Integer.parseInt(split[2])+"";
        }
        bay=split[0]+"-"+split[1]+"-"+split[2]+"-";
        List<CntrInfoVo> cntrList = cntrInfoService.selectCntrBybay(bay);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("bay", bay);
        jsonObject.put("cntrList", cntrList);
        return ResultUtil.build(jsonObject, ResultUtilCodeEnum.SUCCESS);
    }


}
